/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			PrpMdl.h
  \date			june 2010
  \author		TNick

  \brief		Contains the definition of PrpMdl class and related


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PRPMDL_INC__
#define __PRPMDL_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */


class		PrpMdl;
class		PrpNode;
class		PrpTpl;
class		PrpView;
class		EditorDel;

#include	<QAbstractItemModel>
#include	<QModelIndex>
#include	<QVariant>
#include	<QStyledItemDelegate>

#include	<generic/cc_l2d.h>


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/**
*	This class defines an interface that is used by views and delegates to
*	access data. The data itself does not have to be stored in the model;
*	it can be held in a data structure or repository provided by a
*	separate class, a file, a database, or some other application component.
*/
class PrpMdl : public QAbstractItemModel
{
	Q_OBJECT

	//
	//
	//
	//
	/*  DEFINITIONS    --------------------------------------------------------- */

	friend class PrpNode;
	friend class PrpTpl;

	/*  DEFINITIONS    ========================================================= */
	//
	//
	//
	//
	/*  DATA    ---------------------------------------------------------------- */
private:

	/// pointer to first kid
	CC_HDL2D			hd;


	/*  DATA    ================================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ----------------------------------------------------------- */

public:

	/// constructor
	explicit			PrpMdl				(
			QObject		*parent = 0		/**< optional parent object*/
								  );

	/// destructor
	virtual				~PrpMdl				();





	/*		easy access to chain of items (forward)	*/

	/// append an item (insert after last)
	inline void			append	(CC_L2D* pIt)
		{ hd.append(pIt); }
	/// get first item
	inline CC_L2D*		first	(void)
		{ return hd.first(); }
	/// get nth item
	inline CC_L2D*		item	(int i)
		{ return hd.item(i); }
	/// get the number of items
	inline int			count	(void)
		{ return hd.count(); }


	/* alow fellows to trigger change signal */
	inline void			dataHasChanged(QModelIndex the_idx)
		{ emit dataChanged(the_idx, the_idx); }
	inline void			dataHasChanged(QModelIndex the_idx1, QModelIndex the_idx2)
		{ emit dataChanged(the_idx1, the_idx2); }


	inline QModelIndex	createIndex(int row, int col, void* p) const
		{ return QAbstractItemModel::createIndex(row, col, p); }


	/// Returns the index of the item in the model specified by the given row, column and parent index.
	/**
 *	QAbstractItemModel implementation. @n
 *	When reimplementing this function in a subclass,
 *	call createIndex() to generate model indexes that
 *	other components can use to refer to items in your model.
 */
	QModelIndex			index				(
			int						row,
			int						column,
			const					QModelIndex & parent = QModelIndex()
														   ) const;
	/// Returns the parent of the model item with the given index, or QModelIndex() if it has no parent.
	/**
 *	QAbstractItemModel implementation. @n
 *	A common convention used in models that expose tree data
 *	structures is that only items in the first column have
 *	children. For that case, when reimplementing this function
 *	in a subclass the column of the returned QModelIndex would be 0.
 */
	QModelIndex		parent (
			const QModelIndex &		index
			) const;


	/// Returns the number of rows under the given parent.
	/**
 *	QAbstractItemModel implementation. @n
 *	When the parent is valid it means that rowCount is
 *	returning the number of children of parent.
 */
	int				rowCount				(
			const QModelIndex &		parent = QModelIndex()
											 ) const;

	/// Inserts count rows into the model before the given row.
	/**
 *	QAbstractItemModel implementation. @n
 *	The items in the new row will be children of the item
 *	represented by the parent model index. @n
 *	If row is 0, the rows are prepended to any
 *	existing rows in the parent. If row is rowCount(),
 *	the rows are appended to any existing rows in the parent.
 *	If parent has no children, a single column with count rows is inserted. @n
 *	Returns true if the rows were successfully inserted; otherwise returns false.
 */
	bool			insertRows				(
			int						row,
			int						count,
			const QModelIndex &		parent = QModelIndex()
											 ){
			Q_UNUSED(row);
			Q_UNUSED(count);
			Q_UNUSED(parent);
			return false;
		}


	/// Remove rows from model
	/**
 *	QAbstractItemModel implementation. @n
 *	On models that support this, removes count rows starting with the
 *	given row under parent parent from the model. Returns true if
 *	the rows were successfully removed; otherwise returns false.
 *	If you implement your own model, you can reimplement this
 *	function if you want to support removing.
 *	Alternatively, you can provide you own API for altering the data.
 */
	bool			removeRows				(
			int						row,
			int						count,
			const QModelIndex &		parent = QModelIndex()
											 ){
			Q_UNUSED(row);
			Q_UNUSED(count);
			Q_UNUSED(parent);
			return false;
		}

	/// Returns number of columns for this item
	/**
 *	QAbstractItemModel implementation. @n
 */
	virtual int				columnCount				(
			const QModelIndex &		parent = QModelIndex()
											 ) const
		{ Q_UNUSED(parent); return 2; }

	///
	/**
 *	QAbstractItemModel implementation. @n
 *	On models that support this, inserts count new columns into
 *	the model before the given column. The items in each new column
 *	will be children of the item represented by the parent model index. @n
 *	If column is 0, the columns are prepended to any existing columns.  @n
 *	If column is columnCount(), the columns are appended to any existing
 *	columns. If parent has no children, a single row with count columns is inserted. @n
 *	@return  true if the columns were successfully inserted; otherwise returns false.
 */
	bool			insertColumns			(
			int						column,
			int						count,
			const QModelIndex &		parent = QModelIndex()
											 ){
			Q_UNUSED(column);
			Q_UNUSED(count);
			Q_UNUSED(parent);

			return false;
		}

	/// Removes count columns starting with the given column under parent parent from the model.
	/**
 *	QAbstractItemModel implementation. @n
 *	@return true if the columns were successfully removed; otherwise returns false.
 */
	bool			removeColumns			(
			int						column,
			int						count,
			const QModelIndex &		parent = QModelIndex()
											 ){
			Q_UNUSED(column);
			Q_UNUSED(count);
			Q_UNUSED(parent);

			return false;
		}


	/// Returns the data stored under the given role for the item referred to by the index.
	/**
 *	QAbstractItemModel implementation
 */
	QVariant		data					(
			const QModelIndex & index,
			int						role = Qt::DisplayRole
										   ) const;


	/// Sets the role data for the item at index to value.
	/**
 *	QAbstractItemModel implementation. @n
 *	The base class implementation returns false. This function
 *	and data() must be reimplemented for editable models.
 *	Note that the dataChanged() signal must be emitted
 *	explicitly when reimplementing this function.
 *	@return true if successful; otherwise false.
 */
	bool			setData					(
			const QModelIndex &		index,
			const QVariant &		value,
			int						role = Qt::EditRole
										   );


	/// Returns the item flags for the given index.
	/**
 *	QAbstractItemModel implementation. @n
 *	The base class implementation returns a combination of flags that
 *	enables the item (ItemIsEnabled) and allows it
 *	to be selected (ItemIsSelectable).
 */
	Qt::ItemFlags	flags					(
			const QModelIndex &		index
			) const;


	/// Returns the data for the given role and section in the header with the specified orientation.
	/**
 *	QAbstractItemModel implementation
 */
	QVariant		headerData				(
			int						section,
			Qt::Orientation			orientation,
			int						role = Qt::DisplayRole
										   ) const;

	/*  FUNCTIONS    =========================================================== */
	//
	//
	//
	//
};	/*	class PrpMdl	*/
/*  CLASS    =============================================================== */
//
//
//
//

#endif // __PRPMDL_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
